/*
 * Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
 */
package com.pitop.sync.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import com.pitop.sync.api.SyncTraceFeignApi;
import com.pitop.core.exceptions.SyncTraceException;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.Page;
import com.pitop.sync.entity.SyncTrace;


/**
 * 同步追踪
 *
 * @author pi-top
 */
@Service("syncTraceSVImpl")
@Slf4j
public class SyncTraceSVImpl {

    @Autowired
    private SyncTraceFeignApi syncTraceFeignApi;

    /**
     * 加载一个对象SyncTrace
     *
     * @param id id* @param code 编码* @param factoryCode 工厂编码
     * @return SyncTrace
     */
    public SyncTrace load(java.lang.Long id, java.lang.String code, java.lang.String factoryCode) {
        if (id == null && code == null && factoryCode == null) {
            throw new SyncTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return syncTraceFeignApi.load(id, code, factoryCode);
    }

    /**
     * 加载一个对象SyncTrace 通过id
     *
     * @param id id
     * @return SyncTrace
     */
    public SyncTrace loadById(java.lang.Long id) {
        if (id == null) {
            throw new SyncTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return syncTraceFeignApi.loadById(id);
    }

    /**
     * 加载一个对象SyncTrace 通过code
     *
     * @param code 编码
     * @return SyncTrace
     */
    public SyncTrace loadByCode(java.lang.String code) {
        if (code == null) {
            throw new SyncTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return syncTraceFeignApi.loadByCode(code);
    }

    /**
     * 加载一个对象SyncTrace 通过factoryCode
     *
     * @param factoryCode 工厂编码
     * @return SyncTrace
     */
    public SyncTrace loadByFactoryCode(java.lang.String factoryCode) {
        if (factoryCode == null) {
            throw new SyncTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return syncTraceFeignApi.loadByFactoryCode(factoryCode);
    }


    /**
     * 删除对象SyncTrace
     *
     * @param id id* @param code 编码* @param factoryCode 工厂编码
     * @return SyncTrace
     */

    public void delete(java.lang.Long id, java.lang.String code, java.lang.String factoryCode) {
        if (id == null && code == null && factoryCode == null) {
            throw new SyncTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        syncTraceFeignApi.delete(id, code, factoryCode);
    }


    /**
     * 查询SyncTrace分页
     *
     * @param syncTrace 对象
     * @param curPage   当前页
     * @param pageSize  分页条数
     * @return List<SyncTrace>
     */
    public List<SyncTrace> list(SyncTrace syncTrace, int curPage, int pageSize) {
        return syncTraceFeignApi.list(syncTrace, curPage, pageSize);
    }

    /**
     * 查询SyncTrace分页
     *
     * @param id       id* @param code  编码* @param factoryCode  工厂编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<SyncTrace>
     */
    public List<SyncTrace> list(java.lang.Long id, java.lang.String code, java.lang.String factoryCode, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        SyncTrace syncTrace = new SyncTrace();
        syncTrace.setId(id);
        syncTrace.setCode(code);
        syncTrace.setFactoryCode(factoryCode);

        return syncTraceFeignApi.list(syncTrace, curPage, pageSize);
    }


    public int count(java.lang.Long id, java.lang.String code, java.lang.String factoryCode) {
        return syncTraceFeignApi.count(id, code, factoryCode);
    }


    public int count(SyncTrace syncTrace) {
        return syncTraceFeignApi.count(syncTrace);
    }


    /**
     * 保存
     *
     * @param syncTrace 实体
     * @throws BaseException
     */
    public void save(SyncTrace syncTrace) {
        if (syncTrace == null) {
            throw new SyncTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        syncTraceFeignApi.build(syncTrace);
    }

    /**
     * 更新
     *
     * @param syncTrace 实体
     * @throws BaseException
     */
    public void modify(SyncTrace syncTrace) {
        if (syncTrace == null) {
            throw new SyncTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        syncTraceFeignApi.modify(syncTrace);
    }

}
